package com.learning.rpc.order;

import com.learning.rpc.api.order.OrderService;
import com.learning.rpc.config.spring.annocation.EnableRpc;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.CyclicBarrier;

/**
 * ClassName: OrderService
 * Description:
 * Date: 2022/5/10 21:46 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Configuration
@ComponentScan("com.learning.rpc")
@PropertySource("classpath:/rpc.properties")
@EnableRpc
public class OrderServiceApplication {

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(OrderServiceApplication.class);
        context.start();

        final CyclicBarrier cyclicBarrier = new CyclicBarrier(1);
        for (int i = 0; i < 1; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        cyclicBarrier.await();
                        // 测试..模拟调用接口 -- 一定是远程，因为当前的系统没有具体实现类
                        OrderService orderService = context.getBean(OrderService.class);
                        orderService.create("买一瓶水");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }

        System.in.read();
        context.close();
    }

}
